<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var num = 0;
        var interval="";
        var s="";
        function changeImg() {
            var img = document.getElementById("lbt");
            img.src = "img/" + (++num == 3 ? num = 0 : num) + ".png"
            s=img.src;
            var name = document.getElementById("name");
            var strings = img.src.split("/");
            if (strings[strings.length-1].split(".")[0]=="0"){
                name.innerHTML="剪刀";
            } else if (strings[strings.length-1].split(".")[0]=="1") {
                name.innerHTML="石头";
            }else{
                name.innerHTML="布";
            }
        }
        function run1() {
             interval = setInterval(changeImg, 100);
            var showresult = document.getElementById("showresult");
            showresult.innerHTML="";
        }
        function run2() {
            clearInterval(interval);
            var showresult = document.getElementById("showresult");
            showresult.innerHTML="<img id='lbt' src="+s+"/>"
        }
    </script>
</head>
<body>
<div id="onnum" style="height: 180px">
    <img id="lbt" src="img/0.png"/>
</div>
<input type="button" value="开始" onclick="run1()"/>
<input type="button" value="结束" onclick="run2()"/>
<span id="name">剪刀</span>
<div id="showresult">
</div>
</body>
</html>